﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Drawing;
using FacebookWrapper.ObjectModel;
using FacebookWrapper;

namespace B13_Ex02_David_300512340_Alexey_321203689
{
    public class PhotoWrapper
    {
        public Photo PhotoInformation { get; set; }

        public override string ToString()
        {
            return string.Format("{0} ({1})", PhotoInformation.Name, PhotoInformation.UpdateTime);
        }

        public string GetPhotoURL
        {
            get { return PhotoInformation.URL; }
        }

        public void SavePhoto(PhotoWrapper i_Photo, string i_PathSelected, string i_PhotoName)
        {
            Stream photoStrem = new WebClient().OpenRead(i_Photo.PhotoInformation.URL);
            Image image = Image.FromStream(photoStrem);
            string path = string.Format("{0}\\{1}.jpg", i_PathSelected, i_PhotoName);

            try
            {
                image.Save(string.Empty + path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch
            {
                throw new Exception("Unable to save. Please contact the Developers");
            }
        }
    }
}
